package org.example.chapter2;

import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func0;

import java.security.cert.CertificateRevokedException;

public class Demo2_1_2 {
    public static void main(String[] args) {
        Observable<Long> justObservable = getJust();
        justObservable.subscribe(new Action1<Long>() {
            @Override
            public void call(Long aLong) {
                System.err.println("Just:currentTimeMillis = " + aLong);
            }
        });

        Observable<Long> deferObservable = getDefer();
        deferObservable.subscribe(new Action1<Long>() {
            @Override
            public void call(Long aLong) {
                System.err.println("Defer:currentTimeMillis = " + aLong);
            }
        });
    }
    private static Observable<Long> getJust(){
        return Observable.just(System.currentTimeMillis());
    }
    private static Observable<Long> getDefer(){
        return Observable.defer(new Func0<Observable<Long>>() {
            @Override
            public Observable<Long> call() {
                return getDefer();
            }
        });
    }
}
